package com.hd.controller.activiti.util.cmd.util;

import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.impl.pvm.delegate.ActivityExecution;
/**
 * 获取变量
 * @author hzhh123
 * 2018年8月30日下午3:06:33
 */
public class ShareniuLoopVariableUtils {
	public static void setLoopVariable(ExecutionEntity execution,
			String variableName,Object value) {
		//获取执行实例的父级
		ActivityExecution parent = execution.getParent();
		//设置变量
		parent.setVariable(variableName, value);
	}
	
	public static Integer getLoopVariable(ExecutionEntity execution,String variableName) {
		Object value=execution.getVariableLocal(variableName);//获取变量
		//获取执行实例的父级
		ActivityExecution parent = execution.getParent();
		//设置变量
		while(value==null && parent!=null) {
			value=parent.getVariableLocal(variableName);
			parent=parent.getParent();
		}
		return (Integer) (value==null?0:value);
	}
}
